package org.example.game.history;

import java.util.Arrays;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/14 11:18
 */
public class Solution100361 {

    public static void main(String[] args) {
        System.out.println(new Solution100361().minimumCost(6, 3, new int[]{2,3,2,3,1}, new int[]{1,2}));
    }

    public int minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
        Arrays.sort(horizontalCut);
        Arrays.sort(verticalCut);

        int h = 1;
        int l = 1;

        int calH = 1;
        int calL = 1;

        int res = 0;
        while (h < m || l < n){
            int hMax=0, lMax = 0;
            if(m-h-1 >= 0){
                hMax = horizontalCut[m-h-1];
            }
            if(n-l-1 >= 0){
                lMax = verticalCut[n-l-1];
            }

            if(hMax >= lMax){
                res += hMax * calL;
                h++;
                calH++;

                System.out.println("h: " + hMax);
            }else {
                res += lMax * calH;
                l++;
                calL++;
                System.out.println("l: " + lMax);
            }
        }

        return res;
    }

}
